package org.jks.model;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.hibernate.annotations.GenericGenerator;
import org.jks.report.model.ReportDeviceInOut;
import org.jks.util.DateUtil;

import com.google.gson.annotations.Expose;

@Entity
@Table(name = "DeviceInOut")
public class DeviceInOut {
	public static final int TYPE_IN = 1;
	public static final int TYPE_OUT = 2;
	@Id
	@GeneratedValue(generator = "increment")
	@GenericGenerator(name = "increment", strategy = "increment")
	@Expose
	private long Id;
	/**
	 * 1为入库，2为出库
	 */
	@Expose
	private long Type;
	@Column(name = "TdCode", length = 100)
	@Expose
	private String TdCode;
	@Column(name = "No", length = 64)
	@Expose
	private String No;
	@Column(name = "DeviceType", length = 64)
	@Expose
	private String DeviceType;
	@Column(name = "Brand", length = 64)
	@Expose
	private String Brand;
	@Column(name = "Manufacturers", length = 128)
	@Expose
	private String Manufacturers;
	@Column(name = "Model", length = 64)
	@Expose
	private String Model;
	@ManyToOne
	@JoinColumn(name = "Operator", referencedColumnName = "Id", nullable = false)
	@Expose
	private User Operator;
	@Temporal(TemporalType.TIMESTAMP)
	@Expose
	private Date Time;

	public long getId() {
		return Id;
	}

	public void setId(long id) {
		Id = id;
	}

	public long getType() {
		return Type;
	}

	public void setType(long type) {
		Type = type;
	}

	public String getTdCode() {
		return TdCode;
	}

	public void setTdCode(String tdCode) {
		TdCode = tdCode;
	}

	public String getNo() {
		return No;
	}

	public void setNo(String no) {
		No = no;
	}

	public String getDeviceType() {
		return DeviceType;
	}

	public void setDeviceType(String deviceType) {
		DeviceType = deviceType;
	}

	public String getBrand() {
		return Brand;
	}

	public void setBrand(String brand) {
		Brand = brand;
	}

	public String getManufacturers() {
		return Manufacturers;
	}

	public void setManufacturers(String manufacturers) {
		Manufacturers = manufacturers;
	}

	public String getModel() {
		return Model;
	}

	public void setModel(String model) {
		Model = model;
	}

	public User getOperator() {
		return Operator;
	}

	public void setOperator(User operator) {
		Operator = operator;
	}

	public Date getTime() {
		return Time;
	}

	public void setTime(Date time) {
		Time = time;
	}

	public ReportDeviceInOut toReportModel(){
		ReportDeviceInOut rdio = new ReportDeviceInOut();
		rdio.setId(this.Id + "");
		rdio.setNo(this.No);
		rdio.setTdCode(this.TdCode);
		rdio.setDeviceType(this.DeviceType);
		rdio.setBrand(this.Brand);
		rdio.setManufacturers(this.Manufacturers);
		rdio.setModel(this.Model);
		rdio.setOperator(this.Operator.getUsername()+"("+ this.Operator.getName() + ")");
		rdio.setTime(DateUtil.toString(this.Time, "yyyy-MM-dd HH:mm:ss"));
		if(this.Type == TYPE_IN){
			rdio.setType("入库");
		}
		else if(this.Type == TYPE_OUT){
			rdio.setType("出库");
		}
		return rdio;
	}
}
